package org.larkdoc.service.impl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.larkdoc.dao.ProjectRelUserMapper;
import org.larkdoc.model.entity.ProjectRelUser;
import org.larkdoc.service.ProjectRelUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 项目与用户业务功能实现类
 * 
 * @author  zhangpeijun[zhangpeijun1024@qq.com]
 * @version  [v1.0.1, 2017年10月17日]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
@Service("projectRelUserService")
public class ProjectRelUserServiceImpl implements ProjectRelUserService {
    
    @Autowired
    private ProjectRelUserMapper mapper;
    
    @Override
    public int deleteByProjectId(Integer projectId) {
        if (projectId > 0) {
            return mapper.deleteByProjectId(projectId);
        } else {
            return 0;
        }
    }
    
    @Override
    public int insertBatch(List<ProjectRelUser> records) {
        if (CollectionUtils.isNotEmpty(records)) {
            return mapper.insertBatch(records);
        } else {
            return 0;
        }
    }
    
    @Override
    public List<ProjectRelUser> queryByProjectId(Integer projectId) {
        if (projectId > 0) {
            return mapper.queryByProjectId(projectId);
        } else {
            return null;
        }
    }
    
    @Override
    public List<ProjectRelUser> queryByProjectId(List<Integer> projectId) {
        if (CollectionUtils.isNotEmpty(projectId)) {
            return mapper.queryByProjectIds(projectId);
        } else {
            return null;
        }
    }
    
    @Override
    public boolean checkUserBelongProject(Integer projectId, Integer userId) {
        return mapper.checkUserBelongProject(projectId, userId) > 0 ? true : false;
    }
}
